<div class="modal fade bs-modal-md" id="modelContent">
	<div class="modal-dialog modal-md" style="width: 800px;">
		<div class="modal-content"></div>
	</div>
</div>

<div class="portlet box green">
    <div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>企业管理 > 企业列表 > 新增</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
    </div>
    <div class="portlet-body">
    	<div class="portlet-body form">
    	<form role="form" action="/company/add" class="form-horizontal" method="post">
        	<div class="form-body">
        		<h3 class="form-section">基本信息</h3>
        	     <div class="form-group">
                     <label class="control-label col-md-3">企业名称：</label>
                     <div class="col-md-5">
                         <input type="text" maxlength="25" placeholder="25字以内" class="form-control" name="company.name" required onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))">
                     </div>
                 </div>
                 <!-- <h3 class="form-section">负责人信息</h3> -->
                <div class="form-group">
                	<label class="control-label col-md-3">会员号/手机号：</label>
                    <div class="col-md-5">
                        <select class="js-data-user-ajax form-control" name="userinfo.id" required>
						</select>
                    </div>
                </div>
                <!--  <div class="form-group">
                     <label class="control-label col-md-3">企业编号：</label>
                     <div class="col-md-5">
                     </div>
                 </div> -->
                 <input type="hidden" name="company.id" value="$!code" >
                 
                 
                 <div class="form-group">
                     <label class="control-label col-md-3">企业规模：</label>
                     <div class="col-md-5">
                         <select name="scale" class="form-control" >
	                    		<option value="">--请选择规模--</option>
	                    		<option value="LESS1" selected>20人以下</option>
	                    		<option value="LESS2">20-99人</option>
	                    		<option value="LESS3">100-300人</option>
	                    		<option value="LESS4">301-1000人</option>
	                    		<option value="LESS5">1001-5000人</option>
	                    		<option value="LESS6">5000人以上</option>
	                    	</select>
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">公司性质：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" placeholder="例如：民营企业" name="company.nature" onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))">
                     </div>
                 </div>
                 <div class="form-group">
	                	<label class="control-label col-md-3">行业：</label>
	                	<div class="col-md-5">
	                    	<select name="company.industryId" class="form-control" >
	                    		<option value="">请选择行业</option>
	                    		#foreach($industry in $!industryList)
	                    		#if($velocityCount == 1)
	                    		<option value="$industry.id" selected>$industry.name</option>
	                    		#else
	                    		<option value="$industry.id" >$industry.name</option>
	                    		#end
	                    		#end
	                    	</select>
	                	</div>
	             </div>
                 <div class="form-group">
	                	<label class="control-label col-md-3">*企业分类：</label>
	                	<div class="col-md-5">
	                    	<select name="company.cataId" class="form-control" >
	                    		<option value="">请选择分类</option>
	                    		#foreach($cata in $!catalist)
	                    		#if($velocityCount == 1)
	                    		<option value="$cata.id" selected>$cata.name</option>
	                    		#else
	                    		<option value="$cata.id">$cata.name</option>
	                    		#end
	                    		#end
	                    	</select>
	                	</div>
	             </div>
                 <div class="form-group">
 					<label class="control-label col-md-3">企业地区:</label>
 					<div class="col-md-5">
						<select name="company.provinceCode" onchange="getAddress(1, event)" data-id="0"
                                   class="form-control  " style="width: 33.3% ;float: left;" >
                               <option value="">省</option>
                               #foreach($city in $!listCity)
                               <option value="$!city.cityCode">$!city.name</option>
                          	 	#end
                           </select>
                           <select name="company.cityCode" onchange="getAddress(2, event)" data-id="1"
                                   class="form-control  " style="width: 33.3%;float: left;" >
                               <option value="">市</option>
                           </select>
                           <select name="company.countyCode" onchange="getAddress(3, event)" data-id="2"
                                   class="form-control  " style="width: 33.3%;float: left;" >
                               <option value="">区/县</option>
                           </select>
 					</div>
 				 </div>	
 				 <div class="form-group">
                     <label class="control-label col-md-3">详细地址：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" value="企业实际地址" name="company.address">
                     </div>
                 </div>
                 <div class="form-group">
                 	<label class="control-label col-md-3">地区邮编：</label>
                 	<div class="col-md-5">
                         <input type="number"  placeholder="请输入数字" class="form-control" name="company.postcode">
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">企业电话：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="company.phone" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入数字">
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">企业邮箱：</label>
                     <div class="col-md-5">
                         <input type="email" class="form-control" name="company.email" placeholder="请输入邮箱">
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">企业传真：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="company.fax" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入数字">
                     </div>
                 </div>
                 <div class="form-group">
                 	<label class="control-label col-md-3">企业网址:</label>
                 	<div class="col-md-5">
                 		 <input type="text" class="form-control" name="company.webSite">
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">*专管员：</label>
                     <div class="col-md-5">
                          <select name="company.operatorId" class="form-control operatorName">
	                    		<option value="">请选择专管员</option>
	                    		#foreach($user in $!operatorList)
	                    		#if($velocityCount == 1)
	                    		 <option value="$user.id" data-name='$user.username' selected>$user.username</option>
	                    		 #else
	                    		 <option value="$user.id" data-name='$user.username' >$user.username</option>
	                    		 #end	                    		 
	                    		#end
	                    	</select>
	                    	<input type="hidden" id="operatorName" name="operatorName">
                     </div>
                     <script type="text/javascript">
						function operatorName(){
	                    	var _this = $("form .operatorName");
	                    	var operatorName = _this.find("option:selected").attr("data-name");
	                    	$("#operatorName").val(operatorName);
						}
						operatorName();
                    	$("form").on("change",".operatorName",function(){
                    		operatorName()
						})
                    </script>
                 </div>
                  <div class="form-group">
                     <label class="control-label col-md-3">订单免审：</label>
                     <div class="col-md-5">
                         <select name="company.audit" class="form-control" >
	                    		<option value="1">免审核</option>
	                    		<option value="0" selected>审核</option>
	                    	</select>
                     </div>
                 </div>
                 <h3 class="form-section">账户信息</h3>
	                 <div class="form-group">
	                     <label class="control-label col-md-3">信用额度：</label>
	                     <div class="col-md-5">
	                         <input type="text" class="form-control positiveFloatNum" name="company.credits" required   placeholder="请输入数字">
	                     </div>
	                 </div>
	                 <div class="form-group">
		                <label class="control-label col-md-3">实际申请账期时间：</label>
		               <div class="col-md-5">
			                <select name="applyListTime" class="form-control " >
		                             #foreach($billTime in $!billTimes)
		                               <option value="$!billTime" >$!billTime.name</option>
								    #end
		                      </select>
		                </div>
		            </div> 
	                 <div class="form-group">
                     <label class="control-label col-md-3">账单日：</label>
                     <div class="col-md-5">
                          <select name="company.period" class="form-control" required>
	                    		<option value="">--请选择天数--</option>
	                    		#foreach( $i in [1..28])
	                    			#if($velocityCount == 1)	
	                    			<option value="$i" selected>$i</option>
	                    			#else
	                    			<option value="$i" >$i</option>
	                    			#end
	                    		#end
	                    	</select>
                     </div>
                 </div>
                 <div class="form-group">
	                	<label class="control-label col-md-3">企业等级：</label>
	                	<div class="col-md-5">
	                    	<select name="company.level" class="form-control" required>
	                    		<option value="">请选择等级</option>
	                    		#foreach($level in $!levelList)
	                    		#if($velocityCount == 1)
	                    		<option value="$level.id" selected>$level.name</option>
	                    		#else
	                    		<option value="$level.id">$level.name</option>
	                    		#end
	                    		#end
	                    	</select>
	                	</div>
	             </div>
                 <h3 class="form-section">营业执照信息</h3>
                 <div class="form-group">
                     <label class="control-label col-md-3">统一社会信用代码：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="license.registration" >
                     </div>
                 </div>
                 <div class="form-group">
					<label class="control-label col-md-3">营业执照电子版：</label>
					<div class="col-md-4">
	                    <div class="mt-element-overlay">
							<div class="mt-overlay-1 fileinput fileinput-new" data-provides="fileinput" style="margin-bottom: 0;width: auto;;height: auto;">
								<div class="fileinput-new thumbnail" style="width: 150px; height: 150px; margin-bottom: 0">
								    <img src="" alt="上传图片"> 
								</div>
								<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 150px; max-height: 150px;margin-bottom: 0"> </div>
								<div class="mt-overlay">
								    <span class="btn default btn-file" style="padding: 0;">
									    <span class="fileinput-new"> 浏览 </span>
									    <span class="fileinput-exists"> 更改 </span>
									    <input type="file"  class="uploadProdImage" accept="image/jpg,image/gif,image/bmp,image/jpeg,image/png" >  
									     <input type="hidden" name="license.image"    />
								    </span>`
								    <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput" style="padding: 0"> 删除 </a>
								</div>
                        	</div>
						</div>
					</div>
				</div>
				<div class="form-group">
					 <label class="control-label col-md-3">成立日期：</label> 
					 <div class="col-md-2">
							<input class="form-control" type="text" name="license.startTime" id="startTime" value="$!startTime" readonly>
							<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
					</div>
					<label class="control-label col-md-1">有效期限：</label>
					<div class="col-md-2">
							<input class="form-control" type="text" name="license.endTime" id="endTime" value="$!endTime" readonly>
							<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
					</div>
					<div class="col-md-2">
						<label>
						<input type="checkbox" class="icheck group-icheck"/>
						<span>长期</span>
						</label>
					</div>
				</div>
				<div class="form-group">
                     <label class="control-label col-md-3">注册资本：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="license.capital">
                     </div>
                 </div>  
                 <div class="form-group">
 					<label class="control-label col-md-3">住所：</label>
 					<div class="col-md-5">
 						<div id="element_id2" class="row">
 						  <div class="col-md-4">
						  	<select name="license.province" class=" form-control  province"></select>
						  </div>
						  <div class="col-md-4">
						  	<select name="license.city"  class=" form-control  city"></select>
						  </div>
						  <div class="col-md-4">
						  	<select name="license.county"   class=" form-control  area"></select>
						  </div>
						</div>
 					</div>
 				 </div>	
                 <div class="form-group">
                     <label class="control-label col-md-3">地址详情：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="license.address" >
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">法人姓名：</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" name="license.name" >
                     </div>
                 </div>
                 <div class="form-group">
                     <label class="control-label col-md-3">身份证号：</label>
                     <div class="col-md-5">
                         <input type="text" maxlength="18" class="form-control"  name="license.idCard" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入数字不少于18位">
                     </div>
                 </div>      
                 <div class="form-group">
					<label class="control-label col-md-3">身份证电子版：</label>
					<div class="col-md-4">
	                    <div class="mt-element-overlay">
							<div class="mt-overlay-1 fileinput fileinput-new" data-provides="fileinput" style="margin-bottom: 0;width: auto;;height: auto;">
								<div class="fileinput-new thumbnail" style="width: 150px; height: 150px; margin-bottom: 0">
								    <img src="" alt="上传图片"> 
								</div>
								<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 150px; max-height: 150px;margin-bottom: 0"> </div>
								<div class="mt-overlay">
								    <span class="btn default btn-file" style="padding: 0;">
									    <span class="fileinput-new"> 浏览 </span>
									    <span class="fileinput-exists"> 更改 </span>
									    <input type="file"  class="uploadProdImage" accept="image/jpg,image/gif,image/bmp,image/jpeg,image/png" required>  
									     <input type="hidden" name="license.idCardImage"   />
								    </span>`
								    <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput" style="padding: 0"> 删除 </a>
								</div>
                        	</div>
						</div>
					</div>
				</div>
                 
                </div>
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">昵称：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="userinfo.nickname" > -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">*姓名：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="userinfo.realname" required> -->
<!--                      </div> -->
<!--                  </div> -->
			
			
			
<!-- 			 <div class="portlet-title"> -->
<!-- 		          <h2>发票信息</h2> -->
<!--               </div> -->
<!--                 <div class="form-body"> -->
<!--                  <div class="form-group"> -->
<!--                 	<label class="control-label col-md-3">发票类型：</label> -->
<!--                     <div class="col-md-5"> -->
<!--                         <select name="invoice.invoiceType" class="form-control" id="invoicetype"> -->
<!-- 	                    	<option value="ORDINARY" #if($!item.invoiceType=='ORDINARY') selected #end>纸质普通发票</option> -->
<!-- 	                        <option value="VALUEADDED" #if($!item.invoiceType=='VALUEADDED') selected #end>增值税发票</option> -->
<!-- 	                        <option value="NOTNEED" #if($!item.invoiceType=='NOTNEED') selected #end>无发票需求</option> -->
<!-- 	                    </select> -->
<!--                     </div> -->
<!--                 </div> -->
<!-- 				<div class="form-group"> -->
<!--                      <label class="control-label col-md-3">*发票抬头：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="invoice.title" required> -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">*纳税人识别号：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="number" class="form-control" name="invoice.taxpayerNumber" required> -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">发票内容：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="invoice.content" > -->
<!--                      </div> -->
<!--                  </div>         -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">注册地址：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="invoice.companyAddress"> -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">注册电话：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="number" class="form-control" name="invoice.companyPhone" > -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">开户银行：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="text" class="form-control" name="invoice.depositBank" > -->
<!--                      </div> -->
<!--                  </div> -->
<!--                  <div class="form-group"> -->
<!--                      <label class="control-label col-md-3">银行账户：</label> -->
<!--                      <div class="col-md-5"> -->
<!--                          <input type="number" class="form-control" name="invoice.accountBank" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入数字"> -->
<!--                      </div> -->
<!--                  </div>     -->
<!--             </div>  -->
            <div class="form-actions right">
						<a href="javascript:;" thref="/company/list" class="btn green ajax-post"><i class="fa fa-check"></i> 提交</a>
						<a href="/company/list" class="btn btn-outline grey-salsa ajaxify">返回</a>
            </div> 
        </form>     
      </div>
    </div>
</div>
<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script src="/assets/scripts/views-file-add.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript">
$('#element_id').cxSelect({
  url: '/assets/plugins/cxSelect-master/js/cityData.min.json',               // 如果服务器不支持 .json 类型文件，请将文件改为 .js 文件
  selects: ['province', 'city', 'area'],  // 数组，请注意顺序
  emptyStyle: 'none'
});
</script>
<script type="text/javascript">
MyTouchSpin.init();

$('#element_id2').cxSelect({
  url: '/assets/plugins/cxSelect-master/js/cityData.min.json',               // 如果服务器不支持 .json 类型文件，请将文件改为 .js 文件
  selects: ['province', 'city', 'area'],  // 数组，请注意顺序
  emptyStyle: 'none'
});

function formatUser(repo) {
	  if (repo.loading) {
		    return repo.text;
	  }
	var markup = "<div class='select2-result-repository clearfix'>"
					+ "<div class='select2-result-repository__avatar'><img src= '"+repo.imageUrl+"' /></div>"
					+ "<div class='select2-result-repository__meta'>"
							+ "<div class='select2-result-repository__title'>" + repo.id+"</div>"
							+ "<div class='select2-result-repository__description'>"+ repo.realname + "</div>"
							+ "<div class='select2-result-repository__statistics'>"
							+ "<div class='select2-result-repository__forks'><i class='fa fa-flash'></i>手机号 ： "+ repo.phone+ "</div>"
							+ "<div class='select2-result-repository__stargazers'><i class='fa fa-star'></i>  昵称  ："+ repo.nickname+ "</div>"
							+ "<div class='select2-result-repository__watchers'><i class='fa fa-eye'></i>最后登录时间："+(repo.lastLoginTime || "无记录时间 ") + "</div>"
							+"</div>"
						+"</div>"
					+"</div>";
	return markup;
}

function formatRepoSelection(repo) {
	return   repo.id;
}

$(' .js-data-user-ajax').select2({
	ajax : {
		url : "userInfo/getAllUser",
		 dataType: 'json',
		delay : 250,
		async : false,
		data : function(params) {
			var term= params.term ; 
			var map = {};
			if(!isNaN(term)&&term.length != 0){
				map["id"] = parseInt(term); 
				map["phone"] = term; 
				if(parseInt(term) > 2147483647){
					delete va["id"];
				}
			}else{
				map["str"] = term; 
			}
			return {
				id: map["id"], 
				phone: map["phone"], 
				str:map["str"] ,
				pageNo : params.page||1
			};
		},
		processResults: function (data, params) {
		    params.page = params.page || 1;

		    return {
		        results: data.result,
		        pagination: {
		            more: (params.page * 10) < data.totalCount
		        }
		    };
		},
		cache : true
	},
	width : "off",
	escapeMarkup : function(markup) {
		return markup;
	},
	placeholder:'请选择',
	minimumInputLength : 1,
	language: "zh-CN",
	templateResult : formatUser,
	templateSelection : formatRepoSelection
});

</script>

<script type="text/javascript">
function getAddress(type, event){
    var me = $(event.target),
        nextEl = me.next(),
        n_nextEl = nextEl.next(),
        n_n_nextEl = n_nextEl.next(),
        pid = me.val();
    if(me.val() == ''){
        switch (type) {
            case 1: nextEl.html('<option value="">市</option>');
                n_nextEl.html('<option value="">区/县</option>');
                n_n_nextEl.hide();
                break;
            case 2: nextEl.html('<option value="">区/县</option>');
                n_nextEl.hide();
                break;
            case 3: nextEl.hide();
                break;
        }
        return;
    }
    $.get('city/getAddress', { pid: pid }, function(data){
        if(data.length > 0){
            switch (type) {
                case 1: var htmls = '<option value="">市</option>';
                    n_nextEl.html('<option value="">区/县</option>');
                    n_n_nextEl.html('<option value="">街道</option>').hide();
                    break;
                case 2: var htmls = '<option value="">区/县</option>';
                    n_nextEl.html('<option value="">街道</option>').hide();
                    break;
                case 3: var htmls = '<option value="">街道</option>';
                    nextEl.show();
                    break;
            };
            $.each(data, function(index, item){
                htmls += '<option value="'+item.cityCode+'">'+item.name+'</option>';
            })
            nextEl.html(htmls);
        }else{
            switch (type) {
                case 1: n_n_nextEl.hide();
                    break;
                case 2: n_nextEl.hide();
                    break;
                case 3: nextEl.hide();
                    break;
            };
        }
    },'json');
}



$(".uploadProdImage").on("change", function() {
	var target= $(this);
	var files = this.files;
	var formData = new FormData();
	for (var i = 0; i < files.length; i++) {
		var fileSize = parseInt(files[i].size / 1024).toFixed(0);
		if (fileSize > 1024) {
			toastr.warning("单张图片大小不要超过1M");
			return false
		}
		formData.append("file", files[i]);
	}
	;
	$.ajax({
		url : "/upload-shareInfo",
		type : "post",
		data : formData,
		contentType : false,
		processData : false,
		dataType : "html",
		success : function(res) {
			var data = JSON.parse(res);
			target.next().attr('value', data.url);
		}
	})
})

</script>

